<template>
  <view class="locati">
    <!-- 顶部固定栏 -->
    <view class="titlesHead">
      <view class="iconfont icon-fangxiang-xiangzuo icon" @click="yun"></view>
      <view class="titname"> 乐 居 </view>
      <view class="titRight"></view>
    </view>
    <view class="zhanwei">静安阿达</view>
    <!-- 地址列表 -->
    <view class="dingdanList">
      <view
        class="newlist"
        v-for="(item, index) in dizhi"
        :key="item.id"
        @click="TiJiaoweizhi(index)"
      >
        <view class="leftser">
          <view class="namew">
            {{ item.name }}
          </view>
          <view class="pohe">
            {{ item.phoneNumber }}
          </view>
        </view>
        <view class="leftser">
          <view class="imgs" @click="xiudizhi(item.id)">
            <image src="../../static/icons/edit.png" mode=""></image>
          </view>
        </view>
      </view>
    </view>
    <!-- 新增地址按钮 120rpx-->
    <view class="newAddress">
      <view class="address" @click="tiaoxinzeng"> 新 增 地 址 </view>
    </view>
  </view>
</template>

<script>
import { findAllAddress } from "@/api/location/location.js";
export default {
  data() {
    return {
      // 地址数据
      dizhi: {},
      flag: false,
    };
  },
  methods: {
    // 返回上一页
    yun() {
      uni.navigateBack({
        delta: 1,
      });
    },
    // 新增按钮跳转
    tiaoxinzeng() {
      setTimeout(() => {
        uni.navigateTo({
          url: "/pages/location/newLocation/newLocation",
        });
      }, 1500);
    },
    // 提交位置
    TiJiaoweizhi(i) {
      // console.log(this.dizhi[i])
	  // 判断点进来的页面是从哪个地方1进入的，
      if (this.flag) {
        this.$store.state.dizhi = this.dizhi[i];
        uni.navigateBack();
      }
    },
    //  点击修改地址
    xiudizhi(index) {
      console.log(index);
			
      uni.navigateTo({
        url: `/pages/location/amendLoocation/amendLocation/amendLocation?id=${index}`,
      });
    },
  },
  onLoad(option) {
    var result = uni.getStorageSync("token");
    // // console.log(result)
    if (result) {
      findAllAddress().then((res) => {
        console.log(res);
        this.dizhi = res.data.data.items;
      });
    } else {
      uni.showModal({
        title: "登录提示",
        content: "暂未登录，是否立即登录",
        success(res) {
          console.log(res);
          if (res.confirm) {
            uni.navigateTo({
              url: "/pages/login/login",
            });
          }
        },
      });
    }

    //   根据 传过来的值  决定 地址点击是否传输到 VUX上  默认  false
    if (option.type == 1) {
      this.flag = true;
    }
  },
};
</script>

<style lang="less" scoped>
.locati {
  background-color: #f4e8ab;
  height: 100vh;
  position: relative;

  // 头部固定位置
  .titlesHead {
    height: 100rpx;
    width: 100%;
    position: fixed;
    top: 0;
    left: 0;
    color: white;
    display: flex;
    align-items: center;
    background-color: #135a05;
    z-index: 999;

    .icon {
      flex: 1;
      padding-left: 40rpx;
      box-sizing: border-box;
    }

    .titname {
      flex: 3;
      text-align: center;
    }

    .titRight {
      flex: 1;
    }
  }

  // 头部固定后面占位置的盒子，不要删除哈
  .zhanwei {
    width: 100%;
    height: 100rpx;
    background-color: #135a05;
  }

  // 地址列表
  .dingdanList {
    width: 100%;
    padding: 20rpx;
    box-sizing: border-box;
    .newlist {
      width: 100%;
      height: 120rpx;
      font-size: 32rpx;
      border-bottom: 3rpx solid #b4afb0;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .leftser {
      }
      .leftser {
        .imgs {
          width: 40rpx;
          height: 40rpx;

          border-left: 3rpx solid #333333;
          padding-left: 20rpx;
          margin: 0 20rpx;
          image {
            width: 100%;
            height: 100%;
          }
        }
      }
    }
  }

  //新增地址按钮
  .newAddress {
    width: 100%;
    height: 120rpx;
    background-color: #f4e8ab;
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    bottom: 40rpx;
    left: 0;
    .address {
      width: 60%;
      height: 100rpx;
      line-height: 100rpx;
      text-align: center;
      font-size: 40rpx;
      font-weight: 700;

      border-radius: 50rpx;
      background-color: #1d5910;
    }
  }
}
</style>
